package com.qczl.pme.controller.stb;

import java.util.List;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.qczl.core.controller.BaseController;
import com.qczl.model.Json;
import com.qczl.pme.service.LiveService;
import com.qczl.pme.vo.LiveVo;

/**
 * 会议直播控制器
 * 
 * @author SongR
 *
 */
@Controller
@RequestMapping(value = "/stb/live")
public class StbLiveController extends BaseController {
	Logger log = Logger.getLogger(this.getClass());
	
	@Autowired
	LiveService service;
	/**
	 * 开始直播
	 * @return
	 */
	@ResponseBody
	@RequestMapping(value="/start/v1",method={RequestMethod.GET,RequestMethod.POST})
	public Json startLiveV1(String stbno,String topicid,String [] typeid) {
		Json j = new Json();
		try {
			String url = service.startLiveV1(stbno,topicid,typeid);
			j.setMsg("开始直播！");
			j.setResult(url);
		} catch (Exception e) {
			j.setMsg("开始直播失败！");
			j.setSuccess(false);
			log.error("开始直播接口异常！",e);
		}
		return j;
	}
	
	/**
	 * 获取直播列表
	 * @return
	 */
	@ResponseBody
	@RequestMapping(value="/get/v1",method={RequestMethod.GET,RequestMethod.POST})
	public Json getLiveV1(String stbno){
		Json j = new Json();
		try {
			List<LiveVo> vos = service.getLiveV1(stbno);
			if(vos.size()>0){
				j.setMsg("成功获取直播列表！");
				j.setResult(vos);
			}else{
				j.setMsg("暂无直播信息！");
			}
		} catch (Exception e) {
			j.setMsg("获取直播列表失败！");
			j.setSuccess(false);
			log.error("获取直播列表接口异常！",e);
		}
		return j;
	}

	/**
	 * 获取回看列表
	 * @return
	 */
	@ResponseBody
	@RequestMapping(value="/back/v1",method={RequestMethod.GET,RequestMethod.POST})
	public Json getBackV1(String stbno,String topicid,String start,String size){
		Json j = new Json();
		try {
			List<LiveVo> vos = service.getBackV1(stbno,topicid,start,size);
			if(vos.size()>0){
				j.setMsg("成功获取回看列表！");
				j.setResult(vos);
			}else{
				j.setMsg("暂无回看信息！");
			}
		} catch (Exception e) {
			j.setMsg("获取回看列表失败！");
			j.setSuccess(false);
			log.error("获取回看列表接口异常！",e);
		}
		return j;
	}
}
